package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.User;
import cn.itcast.hotel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<User> list(){
        List<User> list = userService.list();
        return list;
    }

    @GetMapping("/findById/{id}")
    public User findById(@PathVariable("id") Integer id){
        User user = userService.getById(id);
        return user;
    }

    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id){
        return userService.removeById(id);
    }


    @PostMapping("/add")
    public boolean add(@RequestBody User user){
        return userService.save(user);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody User user){
        return userService.updateById(user);
    }
}
